package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author: dh
 * @date: 2023-11-03 12:17
 */
@Component
@Aspect
public class MyAdvice {

    @Pointcut("execution(void com.itheima.dao.BookDao.update())")
    public void pt() {};

//    @Before("pt()")
    public void before() {

        System.out.println("before advice ...");
    }

    public void after() {

        System.out.println("after advice ...");
    }

    @Around("pt()")
    public void around(ProceedingJoinPoint pjp) throws Throwable {

        System.out.println("around before advice ...");
        // 对原始操作的调用
        pjp.proceed();
        System.out.println("around after advice ...");
    }

    public void afterReturning() {

        System.out.println("afterReturning advice ...");
    }

    public void afterThrowing() {

        System.out.println("afterThrowing advice ...");
    }
}
